package com.zrq.gencode.domain;

import java.util.HashMap;
import java.util.Map;

/**
 * &#064;author:  zrq1351
 * &#064;date:  2025/10/11
 * @author ZRQ
 */
public enum ColumnType {

	STRING("String",
	       new String[] {"CHAR", "VARCHAR", "NARCHAR", "VARCHAR2", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT"}),

	DATE("Date", new String[] {"DATE", "TIME", "DATETIME", "TIMESTAMP", "YEAR"}),

	INT("Integer", new String[] {"TINYINT", "SMALLINT", "MEDIUMINT"}),

	DOUBLE("Double", new String[] {"DOUBLE"}),

	LONG("Long", new String[] {"INTEGER","BIGINT"}),

	BIGDECIMAL("BigDecimal", new String[] {"DECIMAL"}),

	FLOAT("Float", new String[] {"FLOAT"}),

	BOOLEAN("Boolean", new String[] {"BIT"}),

	BYTE_ARRAY("Byte[]", new String[] {"BLOB"});

	final String javaType;
	final String[] tableType;


	private static final Map<String, String> TYPE_MAPPING = new HashMap<>();

	static {
		// 初始化映射表
		for (ColumnType columnType : ColumnType.values()) {
			for (String tableType : columnType.tableType) {
				TYPE_MAPPING.put(tableType, columnType.javaType);
			}
		}
	}

	ColumnType(String s, String[] strings) {

		this.javaType = s;

		this.tableType = strings;
	}

	public static String getJavaType(String type) {
		String javaType = TYPE_MAPPING.get(type);
		if (javaType != null) {
			return javaType;
		}
		return "String";
	}
}